{% extends 'base.html' %}
{% load humanize %}
{% block page-content %}
{% include 'nav_cat_bar.html' %}
{% load bootstrap %}
{% load mytags %}
<link href="/static/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<link href="/static/css/plugins/dataTables/dataTables.responsive.css" rel="stylesheet">
<link href="/static/css/plugins/dataTables/dataTables.tableTools.min.css" rel="stylesheet">

<div class="wrapper wrapper-content">
<div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{{ tip }}</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="#">未启用 1</a>
                            </li>
                            <li><a href="#">未启用 2</a>
                            </li>
                        </ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <div class="row">

                    {% if error %}
                        <div class="alert alert-warning text-center">{{ error }}</div>
                    {% endif %}
                    {% if msg %}
                        <div class="alert alert-success text-center">{{ msg }}</div>
                    {% endif %}

                        <div class="col-sm-10 m-b-xs">
                            {% for k,v in pro_plat_dict.items %}
                            <div class="btn-group">
                              <button type="button" class="btn btn-primary">{{k}}</button>
                              <button data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn btn-primary dropdown-toggle"><span class="caret"></span></button>
                              <ul class="dropdown-menu dropdown-menu-right">
                                {% for plat_name in v %}
                                  <li><a href="?project={{k}}&platform={{plat_name}}">{{plat_name}}</a></li>
                                  <li class="divider"></li>
                                {% endfor %}
                              </ul>
                            </div>
                            {% endfor %}
                        </div>

                        <div class="col-sm-2 m-b-xs">
                          <button type="button" class="btn btn-primary pull-right" data-toggle="modal" data-target="#web_add"><i class="icon-cogs"></i>添加</button>
                      </div>

                    </div>
                        <div class="table-responsive">
                          <form id="contents_form" name="contents_form">
                            <table class="table table-striped table-bordered table-hover dataTables-example" id="editable" name="editable">
                                <thead>
                                <tr>
                                    <th class="text-center">编号</th>
                                    <th class="text-center">项目</th>
                                    <th class="text-center">平台类型</th>
                                    <th class="text-center">发布仓库</th>
                                    <th class="text-center">域名</th>
                                    <th class="text-center">公网IP</th>
                                   <!-- <th class="text-center">内网IP</th> -->
                                    <th class="text-center">部署目录</th>
                                    <th class="text-center">用途</th>
                                    <th class="text-center">当前版本</th>
                                    <th class="text-center">上次版本</th>
                                    <th class="text-center">最后监测时间</th>
                                    <th class="text-center">状态</th>
                                    <th class="text-center">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for num in web_info %}
                                <tr class="text-center" >
                                    <td name="web_dir_id" value="{{num.domain}}+{{num.p_ip}}" data-editable='false'>
                                        {{forloop.counter}}.<input type="checkbox" data-toggle="checkbox" name="subcheck"   value="{{num.p_ip}}+{{num.web_dir}}+{{ num.domain }}">
                                    </td>
                                    <td data-editable='false'>{{num.project.name}}</td>
                                    <td data-editable='false'>{{num.platform.plat_name}}</td>
                                    <td data-editable='false'><a href="{{ num.repos_name.repos_addr }}/{{ num.domain }}">{{num.repos_name}}</a></td>
                                    <td name="domain">{{num.domain}}</td>
                                    <td data-editable='false'>{{num.p_ip}}</td>
                                 <!--   <td data-editable='false'>{{num.s_ip}}</td> -->
                                    <td name="web_dir">{{num.web_dir}}</td>
                                    <td data-editable='false'>{{num.remark}}</td>
                                    <td data-editable='false'>{{num.version}}</td>
                                    <td data-editable='false'>{{num.last_version}}</td>
                                    {% ifequal num.check_time|date:"Y-m-d H:i:s"|status_diff 1 %}
                                        <td data-editable='false'><font color="green">{{num.check_time|date:"Y-m-d H:i:s"}}</font></td>
                                    {% else %}
                                        <td data-editable='false'><font color="red">{{num.check_time|date:"Y-m-d H:i:s"}}</font></td>
                                    {% endifequal %}

                                    {% ifequal num.status 1%}
                                        <td data-editable='false'><font color="green">{{num.status|web_status}}</font></td>
                                    {% else %}
                                        <td data-editable='false'><font color="red">{{num.status|web_status}}</font></td>
                                    {% endifequal %}

                                    <td data-editable='false'>
                                        <a href="{% url 'web_site_edit' %}?id={{num.id}}"><span class="glyphicon glyphicon-pencil"></span></a>
                                    &nbsp;&nbsp;
                                        <a href="{% url 'web_site_list' %}?id={{num.id}}&action=delete"><span style="color:red" class="glyphicon glyphicon-trash" onclick="return confirm('确认删除吗？')"></span></a>

                                    </td>
                                </tr>
                                {% endfor %}
                                    </tbody>
                            </table>
                            <input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')">全选/全不选
                          </form>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <button type="button" class="btn btn-primary dim"  data-toggle="modal" data-target="#start_nginx" data-whatever="@mdo" onclick="start_nginx()">启动Nginx</button>
                        <button type="button" class="btn btn-danger dim "  data-toggle="modal" data-target="#stop_nginx" data-whatever="@mdo" onclick="stop_nginx()">关闭Nginx</button>
                        <button type="button" class="btn btn-warning dim "  data-toggle="modal" data-target="#restart_nginx" data-whatever="@mdo" onclick="restart_nginx()">平滑重启Nginx</button>
                        <button type="button" class="btn btn-info dim "  data-toggle="modal" data-target="#restart_phpfpm" data-whatever="@mdo" onclick="restart_phpfpm()">重启phpfpm</button>
                </div>
           </div>
        </div>
    </div>
</div>


<div class="modal fade" role="dialog" aria-labelledby="gridSystemModalLabel" id="start_nginx">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel" align="center">启动Nginx服务</h4>
      </div>
      <div class="modal-body">
        <div class="container-fluid" align="center">
        <p id="start_nginx_list"></p>
        </div>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-success" name="switch" value="start_nginx" form="contents_form" formmethod="post" formaction="{% url 'web_site_crontrol' %}?project={{ project }}&platform={{platform}}">确定</button>
        <button type="button" class="btn btn-info" data-dismiss="modal">关闭</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" role="dialog" aria-labelledby="gridSystemModalLabel" id="restart_nginx">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel" align="center">平滑重启Nginx服务</h4>
      </div>
      <div class="modal-body">
        <div class="container-fluid" align="center">
        <p id="restart_nginx_list"></p>
        </div>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-success" name="switch" value="restart_nginx" form="contents_form" formmethod="post" formaction="{% url 'web_site_crontrol' %}?project={{ project }}&platform={{platform}}">确定</button>
        <button type="button" class="btn btn-info" data-dismiss="modal">关闭</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" role="dialog" aria-labelledby="gridSystemModalLabel" id="stop_nginx">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel" align="center">关闭Nginx服务</h4>
      </div>
      <div class="modal-body">
        <div class="container-fluid" align="center">
        <p id="stop_nginx_list"></p>
        </div>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-success" name="switch" value="stop_nginx" form="contents_form" formmethod="post" formaction="{% url 'web_site_crontrol' %}?project={{ project }}&platform={{platform}}">确定</button>
        <button type="button" class="btn btn-info" data-dismiss="modal">关闭</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" role="dialog" aria-labelledby="gridSystemModalLabel" id="restart_phpfpm">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel" align="center">重启php-fpm服务</h4>
      </div>
      <div class="modal-body">
        <div class="container-fluid" align="center">
        <p id="restart_phpfpm_list"></p>
        </div>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-success" name="switch" value="restart_phpfpm" form="contents_form" formmethod="post" formaction="{% url 'web_site_crontrol' %}?project={{ project }}&platform={{platform}}">确定</button>
        <button type="button" class="btn btn-info" data-dismiss="modal">关闭</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" id="web_add" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel" align="center">添加网站</h4>
      </div>
        <div class="modal-body">
            <form id="WebSiteForm" method="post" class="form-horizontal">
                {{ af.project|bootstrap_horizontal }}
                {{ af.platform|bootstrap_horizontal }}
                {{ af.repos_name|bootstrap_horizontal }}
                {{ af.domain|bootstrap_horizontal }}
                {{ af.p_ip|bootstrap_horizontal }}
                {{ af.s_ip|bootstrap_horizontal }}
                {{ af.web_dir|bootstrap_horizontal }}
                {{ af.remark|bootstrap_horizontal }}
                {{ af.version|bootstrap_horizontal }}
                {{ af.admin_user|bootstrap_horizontal }}
            </form>
        </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary" form="WebSiteForm" formmethod="post" formaction="{% url 'web_site_list' %}" name="action" value="add">确定</button>
      </div>
    </div>
  </div>
</div>

<script src="/static/js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.responsive.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.tableTools.min.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        $('#editable').editableTableWidget({editor: $('<textarea>')});
    });

    $(document).ready(function() {
            $('.dataTables-example').dataTable({
                responsive: true,
                "dom": 'T<"clear">lfrtip',
                "iDisplayLength":50,
                "tableTools": {
                    "aButtons":["copy","xls",'print'],
                    "sSwfPath": "/static/js/plugins/dataTables/swf/copy_csv_xls_pdf.swf"
                }
            });
        });
</script>

{%endblock%}
